package com.woniuxy.carrental.controller;

import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.entity.Store;
import com.woniuxy.carrental.service.StoreService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-09-28 15:43
 */
@CrossOrigin  //解决跨域
@RestController  //要求返回json格式数据异步使用
public class StoreController {

    @Resource
    StoreService storeService;

   //新增门店
    @GetMapping("/addStore")
    public String addSt(Store store){
        storeService.addStore(store);
        System.out.println("kankanaknkan:"+store);
        return "添加成功";
    }

    //修改门店信息
    @PutMapping("/updataStore")
    public String updataSt(@RequestBody Store store){

        storeService.updataStoreService(store);
        System.out.println(store);
        return "修改成功";
    }

    //查询所有门店信息
    @RequestMapping("/selectStore")
    public List<Store> selectAll(){
       return storeService.selectAllStoreService();
    }

    //删除门店根据id
    @DeleteMapping("/deleteStore/{storeid}")
    public String deleteSt(@PathVariable int storeid){
        System.out.println(storeid);
    storeService.deleteStoreService(storeid);
    return "删除成功！";
    }

    //测试使用分页
    @RequestMapping("/fenyestore")
    public ResponseResult<PageBean<Store>> fenyeStore(
            Store store,int pageSize,int pageIndex){
       return storeService.selectStoresByPageService(store, pageIndex, pageSize);
    }



}
